home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
228_01
/
msweep.c
< prev
next >
Wrap
Text File
|
1987-07-29
|
15KB
|
831 lines
/*
HEADER: CUGXXX;
TITLE: MS-DOS file utility;
DATE: 6-2-85;
DESCRIPTION: MS-DOS file utility based on CP/M NSWEEP;
KEYWORDS: File organizer, file utility;
FILENAME: MSWEEP.C;
WARNINGS: None;
AUTHORS: Ferdinand Knerlich;
COMPILER: DeSmet C;
REFERENCES: US-DISK 1308;
ENDREF
*/
/* mswp ver. 1.00 release prototype 6-2-85
ms-dos file manipulation utility
based on the cp/m nsweep program
written by ferdinand knerlich, 6-2-85
*/
#define SP 32
#define CR 13
#define DC3 19
#define EOF -1
#define ERR -1
#define unsn unsigned
struct {
char dta_reserved[21];
char dta_attribute;
short int dta_time;
short int dta_date;
long int dta_file_size;
char dta_name[13];
} DTA;
struct d_entry{
char e_attribute;
short int e_time;
short int e_date;
long int e_file_size;
char e_name[13];
char e_tag;
int e_num;
} entry[500];
int entries;
int num;
int fil1,fd1,fd2;
char e_buf[40];
char f_buf[40];
char dest_buf[40];
char files[] = "*.*";
char drv[5] = " :";
char ddrv[5] = " ";
int long_format = 0;
int time_sort = 0;
int reverse_order = 0;
int single_column = 0;
int showhide = 0;
char volume[13];
unsn avail,total,sectors,bytes;
main(argc, argv)
short int argc; char *argv[];
{
char devarg[85];
char fname[20];
int c,d,tag,prpt;
int xit,j,lncnt,def_drv;
long int tag_tot,totu,tota;
char fc,nc,cur_dsk;
char tag,prpt;
char ver;
/* set the Data Transfer Address to the local block */
#asm
mov dx, offset DTA_
mov ah, 01AH ; set disk transfer address
int 21H
#
scr_clr();
scr_rowcol(0,0);
printf("\n* msweep file utility * ver 1.00 6-2-85 ferdinand knerlich\n");
printf(" [press '?' key for help : 'X' key to eXit]");
entries = xit = num = 0;
ver = 0;
def_drv = (drv[0] = cur_drv()) - 'A';
strcat(devarg,files);
if (argc > 1)
{
drv[0] = toupper(argv[1][0]);
}
tag_tot = 0;
login(drv[0]);
while(!(xit))
{
if(entries > 0) display_e(num);
else printf("\nno files\n");
fc = tolower(ci()); if (!fc) nc = tolower(ci());
switch(fc) {
case SP: case CR : /* forward */
if (num > entries-2) {
num = 0;
co('\n'); }
else num++;
break;
case 'a': /* retag */
for( j=0; j<=entries;j++)
{
if(entry[j].e_tag == 1)
{ entry[j].e_tag = 2;
tag_tot += entry[j].e_file_size;
fmtebuf(j);
printf("\n %14s %6D retagged",
e_buf,
tag_tot);
}
}
break;
case 'b': /* back one */
if (num < 1) {
num = entries-1;
co('\n'); }
else num--;
break;
case 'c': /* copy */
printf("to drive ? ");
do
(c=toupper(getchar()));
while (!(c >= 'A' && c <= 'Z' ));
ddrv[0] = c; ddrv[1] = ':'; ddrv[2] = '\0';
fmtebuf(num);
cope(num);
break;
case 'd': /* delete */
printf(" really (y/n) ? ");
c=toupper(getchar());
if(c=='Y')
{
fmtebuf(num);
del(e_buf,num);
}
break;
case 'e': /* erase t/u */
tag = 0;
printf("\ntagged or untagged (t/u) ? ");
tag = toupper(getchar());
if (tag)
{
printf("\nprompt (y/n) ? ");
prpt = toupper(getchar());
if (prpt != 'N') prpt = 'Y';
for( j=0; j<=(entries-1);j++)
{
if(entry[j].e_tag == 2 && tag=='T')
{
tag_tot -= entry[j].e_file_size;
entry[j].e_tag = 1;
fmtebuf(j);
if (prpt == 'Y')
{
printf("\ndelete %14s (y/n) ? ",e_buf);
c=toupper(getchar());
if(c=='Y')
{
printf("\ndeleting %14s",e_buf);
del(e_buf,j);
j--;
}
}
else {
printf("\ndeleting %14s",e_buf);
del(e_buf,j);
j--;
}
}
else if(entry[j].e_tag != 2 && tag=='U')
{
fmtebuf(j);
if (prpt == 'Y')
{
printf("\ndelete %14s (y/n) ? ",e_buf);
c=toupper(getchar());
if(c=='Y')
{
printf("\ndeleting %14s",e_buf);
del(e_buf,j);
j--;
}
}
else {
printf("\ndeleting %14s",e_buf);
del(e_buf,j);
j--;
}
}
}
}
break;
case 'f': /* find */
break;
case 'g': /* chg attributes */
break;
case 'l': /* log new dir */
printf(" drive ? ");
do
(c=toupper(getchar()));
while (!(c >= 'A' && c <= 'Z' ));
drv[0] = c ;
login(drv[0]);
tag_tot = 0;
break;
case 'm': /* mass file copy */
printf("to drive ? ");
do
(c=toupper(getchar()));
while (!(c >= 'A' && c <= 'Z' ));
ddrv[0] = c; ddrv[1] = ':'; ddrv[2] = '\0';
tag = 0;
printf("\ntagged or untagged (t/u) ? ");
tag = toupper(getchar());
if (tag)
{
printf("\nprompt (y/n) ? ");
prpt = toupper(getchar());
if (prpt != 'N') prpt = 'Y';
for( j=0; j<=(entries-1) ;j++)
{
if(entry[j].e_tag == 2 && tag=='T')
{
tag_tot -= entry[j].e_file_size;
entry[j].e_tag = 1;
fmtebuf(j);
if (prpt == 'Y')
{
printf("\ncopy %14s (y/n) ? ",e_buf);
c=toupper(getchar());
if(c=='Y') cope(j);
}
else cope(j);
}
else if(entry[j].e_tag != 2 && tag=='U')
{
fmtebuf(j);
if (prpt == 'Y')
{
printf("\ncopy %14s (y/n) ? ",e_buf);
c=toupper(getchar());
if(c=='Y') cope(j);
}
else cope(j);
}
}
}
break;
case 'r': /* rename */
if(get_f(fname))
{
fmtebuf(num);
if(rename(e_buf,fname) != -1)
{
printf(" rename successful !\n");
strcpy(entry[num].e_name,fname);
}
else printf(" error, not renamed \n");
}
break;
case 's': /* stats */
cur_dsk = cur_drv();
printf(" drive ? ");
do
(c=toupper(getchar()));
while (!(c >= 'A' && c <= 'Z' ));
chg_drv( (int)c - 'A');
totu = tota = avail = total = sectors = bytes = 0;
free_drv(0);
totu = ((long)total - (long)avail) * (long)sectors * (long)bytes;
tota = (long)avail * (long)sectors * (long)bytes;
printf("\n\ndrive %c: has %8D used / %8D free \n",
c,
totu,
tota );
chg_drv( (int)cur_dsk - 'A' );
break;
case 't': /* tag file */
if( (entry[num].e_tag==0) || (entry[num].e_tag==1) )
{
entry[num].e_tag = 2;
tag_tot += entry[num].e_file_size;
printf(" %6D ",tag_tot);
}
else if( entry[num].e_tag==2 )
printf(" %6D",tag_tot);
if (num > entries-2)
{
num = 0;
co('\n');
}
else num++;
break;
case 'u': /* untag file */
if( entry[num].e_tag==2 )
{
entry[num].e_tag = 0;
tag_tot -= entry[num].e_file_size;
printf(" %6D ",tag_tot);
}
else if(( entry[num].e_tag==0 ) || ( entry[num].e_tag==1) )
printf(" %6D",tag_tot);
if (num > entries-2)
{
num = 0;
co('\n');
}
else num++;
break;
case 'v': /* view file */
fmtebuf(num);
if (strlen(drv)>1)
{ strcpy(f_buf,drv);
strcat(f_buf,e_buf);}
else strcpy(f_buf,e_buf);
scr_clr();
scr_rowcol(0,0);
if (!(fil1 = fopen(f_buf,"r")))
{
printf("\nopen error\n");
break;
}
printf("Press 'S' to freeze/unfreeze display and 'X' to quit view.\n");
putchar('\n');putchar('\n');
while ((c=fgetc(fil1)) != EOF && d != 'x')
{
d=tolower(scr_csts());
if (d=='s') while(!scr_csts());
putchar(c);
}
d=' ';
putchar('\n');
fclose(fil1);
break;
case 'w': /* wildcard tag */
break;
case 'q':case 'x': /* exit */
xit = 1;
break;
case 'y': /* set verifY on */
ver = 1 - ver;
ver = set_ver(ver);
printf("\n\nverify is now: ");
(ver ? printf("on\n") : printf("off\n"));
break;
case '?': /* display help file */
scr_clr();
scr_rowcol(0,0);
printf("\n\n* msweep file utility * ver 1.00 6-2-85 ferdinand kner